﻿/*
 * Copyright(C) 2012,ajayumi 保留所有权利。( All rights reserved. )
 * 
 * 文件名称：TripleDESCryptoProvider.cs
 * 摘    要：
 * 当前版本：1.0
 * 作    者：黄乙冬 (ajayumi)
 * 创建日期：2012年6月10日星期日
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace ajayumi.Platform.Core.Security
{
    /// <summary>
    /// TripleDESCryptoProvider
    /// </summary>
    public class TripleDESCryptoProvider : SymmetricCryptoProvider
    {
        #region Variables

        /// <summary>
        /// 默认密钥
        /// </summary>
        private const string DEFAULT_KEY = "A1BC1FE843B9E5F911D2A1BC1FB8431CE5F911D2213451AD";

        #endregion

        #region Properties

        #endregion


        public TripleDESCryptoProvider()
            : base("TripleDESCryptoProvider")
        {
        }

        protected override void Init()
        {
            if (this.SymAlg == null)
            { this.SymAlg = new TripleDESCryptoServiceProvider(); }

            if (string.IsNullOrEmpty(this.CryptoKey) || this.CryptoKey.Length != 48)
            {
                this.CryptoKey = DEFAULT_KEY;
            }
            this.SymAlg.Key = this.HexToByte(this.CryptoKey);
            byte[] iv = new byte[8];
            for (int i = 0; i < 8; i++)
            {
                iv[i] = this.SymAlg.Key[i];
            }
            this.SymAlg.IV = iv;
        }

    }
}
